home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_apache2.idb / usr / freeware / apache2 / include / apr_global_mutex.h.z / apr_global_mutex.h
C/C++ Source or Header  |  2002-07-08  |  7KB  |  188 lines

  1. /* ====================================================================
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Apache" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  */
  54.  
  55. #ifndef APR_GLOBAL_MUTEX_H
  56. #define APR_GLOBAL_MUTEX_H
  57.  
  58. #include "apr.h"
  59. #include "apr_proc_mutex.h"    /* only for apr_lockmech_e */
  60. #include "apr_pools.h"
  61. #include "apr_errno.h"
  62.  
  63. #ifdef __cplusplus
  64. extern "C" {
  65. #endif /* __cplusplus */
  66.  
  67. /**
  68.  * @file apr_global_mutex.h
  69.  * @brief APR Global Locking Routines
  70.  */
  71.  
  72. /**
  73.  * @defgroup APR_GlobalMutex Global Locking Routines
  74.  * @ingroup APR
  75.  * @{
  76.  */
  77.  
  78. #if !APR_PROC_MUTEX_IS_GLOBAL || defined(DOXYGEN)
  79.  
  80. typedef struct apr_global_mutex_t apr_global_mutex_t;
  81.  
  82. /*   Function definitions */
  83.  
  84. /**
  85.  * Create and initialize a mutex that can be used to synchronize both
  86.  * processes and threads. Note: There is considerable overhead in using
  87.  * this API if only cross-process or cross-thread mutual exclusion is
  88.  * required. See apr_proc_mutex.h and apr_thread_mutex.h for more
  89.  * specialized lock routines.
  90.  * @param mutex the memory address where the newly created mutex will be
  91.  *        stored.
  92.  * @param fname A file name to use if the lock mechanism requires one.  This
  93.  *        argument should always be provided.  The lock code itself will
  94.  *        determine if it should be used.
  95.  * @param mech The mechanism to use for the interprocess lock, if any; one of
  96.  * <PRE>
  97.  *            APR_LOCK_FCNTL
  98.  *            APR_LOCK_FLOCK
  99.  *            APR_LOCK_SYSVSEM
  100.  *            APR_LOCK_POSIXSEM
  101.  *            APR_LOCK_PROC_PTHREAD
  102.  *            APR_LOCK_DEFAULT     pick the default mechanism for the platform
  103.  * </PRE>
  104.  * @param pool the pool from which to allocate the mutex.
  105.  * @warning Check APR_HAS_foo_SERIALIZE defines to see if the platform supports
  106.  *          APR_LOCK_foo.  Only APR_LOCK_DEFAULT is portable.
  107.  */
  108. APR_DECLARE(apr_status_t) apr_global_mutex_create(apr_global_mutex_t **mutex,
  109.                                                   const char *fname,
  110.                                                   apr_lockmech_e mech,
  111.                                                   apr_pool_t *pool);
  112.  
  113. /**
  114.  * Re-open a mutex in a child process.
  115.  * @param mutex The newly re-opened mutex structure.
  116.  * @param fname A file name to use if the mutex mechanism requires one.  This
  117.  *              argument should always be provided.  The mutex code itself will
  118.  *              determine if it should be used.  This filename should be the 
  119.  *              same one that was passed to apr_global_mutex_create().
  120.  * @param pool The pool to operate on.
  121.  * @remark This function must be called to maintain portability, even
  122.  *         if the underlying lock mechanism does not require it.
  123.  */
  124. APR_DECLARE(apr_status_t) apr_global_mutex_child_init(
  125.                               apr_global_mutex_t **mutex,
  126.                               const char *fname,
  127.                               apr_pool_t *pool);
  128.  
  129. /**
  130.  * Acquire the lock for the given mutex. If the mutex is already locked,
  131.  * the current thread will be put to sleep until the lock becomes available.
  132.  * @param mutex the mutex on which to acquire the lock.
  133.  */
  134. APR_DECLARE(apr_status_t) apr_global_mutex_lock(apr_global_mutex_t *mutex);
  135.  
  136. /**
  137.  * Attempt to acquire the lock for the given mutex. If the mutex has already
  138.  * been acquired, the call returns immediately with APR_EBUSY. Note: it
  139.  * is important that the APR_STATUS_IS_EBUSY(s) macro be used to determine
  140.  * if the return value was APR_EBUSY, for portability reasons.
  141.  * @param mutex the mutex on which to attempt the lock acquiring.
  142.  */
  143. APR_DECLARE(apr_status_t) apr_global_mutex_trylock(apr_global_mutex_t *mutex);
  144.  
  145. /**
  146.  * Release the lock for the given mutex.
  147.  * @param mutex the mutex from which to release the lock.
  148.  */
  149. APR_DECLARE(apr_status_t) apr_global_mutex_unlock(apr_global_mutex_t *mutex);
  150.  
  151. /**
  152.  * Destroy the mutex and free the memory associated with the lock.
  153.  * @param mutex the mutex to destroy.
  154.  */
  155. APR_DECLARE(apr_status_t) apr_global_mutex_destroy(apr_global_mutex_t *mutex);
  156.  
  157. /**
  158.  * Get the pool used by this global_mutex.
  159.  * @return apr_pool_t the pool
  160.  */
  161. APR_POOL_DECLARE_ACCESSOR(global_mutex);
  162.  
  163. #else /* APR_PROC_MUTEX_IS_GLOBAL */
  164.  
  165. /* Some platforms [e.g. Win32] have cross process locks that are truly
  166.  * global locks, since there isn't the concept of cross-process locks.
  167.  * Define these platforms in terms of an apr_proc_mutex_t.
  168.  */
  169.  
  170. #include "apr_proc_mutex.h"
  171.  
  172. #define apr_global_mutex_t          apr_proc_mutex_t
  173. #define apr_global_mutex_create     apr_proc_mutex_create
  174. #define apr_global_mutex_child_init apr_proc_mutex_child_init
  175. #define apr_global_mutex_lock       apr_proc_mutex_lock
  176. #define apr_global_mutex_trylock    apr_proc_mutex_trylock
  177. #define apr_global_mutex_unlock     apr_proc_mutex_unlock
  178. #define apr_global_mutex_destroy    apr_proc_mutex_destroy
  179. #define apr_global_mutex_pool_get   apr_proc_mutex_pool_get
  180.  
  181. #endif
  182.  
  183. #ifdef __cplusplus
  184. }
  185. #endif
  186.  
  187. #endif  /* ndef APR_GLOBAL_MUTEX_H */
  188.